/**
 * 未结明细页面
 */
var weijieUI = function() {
    var self = this;

    self.table = null;
    self.phone = false;
};
weijieUI.prototype = {};

weijieUI.prototype.init = function() {
    var self = this;
    Lottery.cb = function() {
        stopLoading();
        self.fillTable();
    };
    startLoading();
    Lottery.refresh_uncheck();
}

weijieUI.prototype.fillTable = function() {
    var self = this;
    if (!self.table) return;

    self.table.empty();
    if (Util.isEmpty(context.bets)) {
        self.table.html("<tr><td colspan='6'>暂无数据！</td></tr>");
        $(".sum").html('下注总金额：<span class="red">0.00</span><br/>可赢总金额：<span class="red">0.00</span>');
        return;
    }

    var hasData = false;
    var t1 = 0, t2 = 0;
    for (var type in context.bets) {
        var bets = context.bets[type];
        for (var issue in bets) {
            var list = bets[issue];
            var data = Lottery.combineGroup(list);

            for (var target in data) {
                var o = data[target];
                if (o.state != 0) continue;
                var target = o.target;
                if (o.group) {
                    var target = o.group.split("_")[0];
                }
                else
                    var target = Util.convertTarget(o.type, o.target);
                var tr = $("<tr></tr>");
                if (!self.phone) {
                    tr.append("<td>" + new Date(o.time).Format("MM-dd HH:mm") + "</td>");
                    tr.append("<td>" + get_game_display_name(type) + " 第<span class='blue'>" + issue + "</span>期</td>");
                    tr.append("<td><span class='blue'>" + target + "<span>@<span class='gray'>" + o.rate + "</span></td>");
                    tr.append("<td class='red'>" + (o.amount / 100) + "</td>");
                    tr.append("<td>" + (o.back ? o.back*100 : 0) + "%</td>");
                }
                
                // 计算可赢金额
                var v = o.amount * (o.rate - 1);
                var v2 = o.amount * (o.rate - 1) / 100;
                if (o.back) {
                    v2 += o.back * o.amount/100;
                }
                v2 = v2.toFixed(3);
                tr.append("<td class='red'>" + v2 + "</td>");
                self.table.append(tr);
                hasData = true;
                t1 += o.amount;
                t2 += v;
            }
        }
    }
    if (!hasData) self.table.html("<tr><td colspan='6'>暂无数据！</td></tr>");
    $(".sum").html('下注总金额：<span class="red">' + (t1/100).toFixed(2) +
        '</span><br/>可赢总金额：<span class="red">' + (t2/100).toFixed(3) +
        '</span>');
}

window.WeiJieUI = new weijieUI();